package com.sservice.web.controller.admin;

import com.sservice.base.entity.dto.BaseResult;
import com.sservice.common.SameUrlData;
import com.sservice.commonBusiness.e.DataR;
import com.sservice.commonBusiness.e.File;
import com.sservice.commonBusiness.service.DataRService;
import com.sservice.commonBusiness.service.FileService;
import com.sservice.service.service.IUserService;
import com.sservice.urp.dao.IUserDao;
import com.sservice.urp.vo.UserVo;
import com.sservice.web.common.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.InvocationTargetException;

/**
 *精准普法
 */
@Controller
@RequestMapping("/admin/dataillaw")
public class DetailLawController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Autowired
    private IUserService userService;
    @Autowired
     DataRService dataRService;
    @Autowired
     FileService fileService;
    /**
     * 文件用户关联建立
     *
     * @return
     */
    @SameUrlData
    @ResponseBody
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public BaseResult<Object> create( File file,HttpServletRequest request) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
            DataR data = new DataR();
            UserVo u = userService.getLoginedUser(request);
            String type1=request.getParameter("type1");
            String ss=request.getParameter("id");
            data.setSourceId(Integer.parseInt(ss));
            data.setType1(type1 );
            data.setComId(String.valueOf(u.getId()));
            file.setComId(String.valueOf(u.getId()));
            dataRService.insertSelective(data);
            return new BaseResult(true, String.valueOf(fileService.updateByPrimaryKeySelective(file)), 200);
            }

}
